package york.Game.Unit;

import java.awt.Color;
import java.awt.Point;

import york.Game.Vector2D;
/** Unit<br>
 * Position - Self Explanatory<br>
 * Shape - The shape to draw for this unit<br>
 * 	- Circle<br>
 *  - Square<br>
 *  - Triangle<br>
 * Color - The color to fill the unit in with<br>
 * Size - The scale of the shape being drawn<br>
 * Direction - The direction the unit is facing/moving
 */
public class Unit {
	private Vector2D position;
	String shape;
	Color color;
	private float size;
	double direction;
	
	public Unit() {
		setPosition(new Vector2D());
		shape = "None";
		//r g b a
		color = new Color(0,0,1.0f,1.0f);
		setSize(10);
		direction = 0;
	}
	
	public Unit(Point a_Pos,String a_Shape,float a_Size) {
		getPosition().set(a_Pos);
		shape = a_Shape;
		color = new Color(0,0,1.0f,1.0f);
		setSize(a_Size);
		direction = 0;
	}
	
	public void Init(Color a_Color,double a_Direction) {
		color = a_Color;
		direction = a_Direction;
	}
	
	/*
	 * Calculates the direction based on the new place to move to.
	 */
	public void MoveTo(int X,int Y){
		double Displacement = Math.sqrt(Math.pow(X - getPosition().x, 2) + Math.pow(Y - getPosition().y, 2));
		direction = Math.asin( Y / Displacement );
		getPosition().x += X;
		getPosition().y += Y;
	}
	
	public boolean Within(Vector2D a_Position) {
		if(getPosition().distance(a_Position) <= getSize())
			return true;
		return false;
	}

	public Vector2D getPosition() {
		return position;
	}

	public void setPosition(Vector2D position) {
		this.position = position;
	}

	public float getSize() {
		return size;
	}

	public void setSize(float size) {
		this.size = size;
	}
}
